package com.sdgakj.utils;

import com.google.common.collect.ImmutableTable;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.math.BigDecimal;

/**
 * @author limengyang 2016/11/11
 * 估价
 */
public class Valuation {

    private static final Logger  logger = LoggerFactory.getLogger(Valuation.class);

    //载货  年-月-估价
    public static ImmutableTable<Integer,Integer,BigDecimal>  carryTable = null;

    //城建
    public static ImmutableTable<Integer,Integer,BigDecimal>  cityTable = null;

    //建筑工地
    public static ImmutableTable<Integer,Integer,BigDecimal>  constructionTable  = null;


    static {
        ImmutableTable.Builder<Integer,Integer,BigDecimal> carryBuilder = ImmutableTable.builder();

        double[]  one =  new double[]{0.8,0.983,0.967,0.95,0.933,0.917,0.9,
                                      0.883,0.867,0.85,0.833,0.817,0.8};

        double[]  two  = new double[]{0.64, 0.787, 0.773, 0.76, 0.747, 0.733, 0.72,
                                      0.707, 0.693, 0.68, 0.667, 0.653, 0.64};

        double[]  three = new double[]{0.566,0.634,0.628,0.622,0.615,0.609,0.603,
                                       0.597,0.591,0.585,0.579,0.572,0.566};

        double[]  four = new double[]{0.493,0.56,0.554,0.548,0.542,0.536,0.529,
                                     0.523,0.517,0.511,0.505,0.499,0.493};

        double[]  five = new double[]{0.419,0.486,0.48,0.474,0.468,0.462,0.456,
                                     0.449,0.443,0.437,0.431,0.425,0.419};

        double[]  six = new double[]{0.345,0.413,0.406,0.4,0.394,0.388,0.382,
                                      0.376,0.37,0.363,0.357,0.351,0.345};

        double[]  seven = new double[]{0.271,0.339,0.333,0.327,0.32,0.314,0.308,
                                       0.302,0.296,0.29,0.284,0.277,0.271};

        double[]  eight = new double[]{0.198,0.265,0.259,0.253,0.247,0.241,0.234,
                                       0.228,0.222,0.216,0.21,0.204,0.198};

        double[]  nine = new double[]{0.124,0.191,0.185,0.179,0.173,0.167,0.161,
                                      0.154,0.148,0.142,0.136,0.13,0.124};

        double[]  ten  = new double[]{0.05,0.118,0.111,0.105,0.099,0.093,0.087,
                                      0.081,0.075,0.068,0.062,0.056,0.05};

        double[][]  all = new double[][]{one,two,three,four,five,six,seven,eight,nine,ten};
        for (int y = 1; y <= 10; y++) {
            for (int m = 0; m <= 12; m++) {
                carryBuilder.put(y,m,new BigDecimal(all[y - 1][m]));
                logger.info(y + "#" + m + "#" + all[y - 1][m]);
            }
        }

         one = two = three = four = five = six = seven = eight = nine = ten = null;
         all = null;
        carryTable = carryBuilder.build();
    }


    static {
        ImmutableTable.Builder<Integer,Integer,BigDecimal>   cityBuilder = ImmutableTable.builder();

        double[] one = new double[]{0.8,0.983,0.967,0.95,0.933,0.917,0.9,
                0.883,0.867,0.85,0.833,0.817,0.8};

        double[] two = new double[]{0.717,0.793,0.786,0.779,0.772,0.765,0.758,
                0.751,0.744,0.738,0.731,0.724,0.717};

        double[] three = new double[]{0.633,0.71,0.703,0.696,0.689,0.682,0.675,
                0.668,0.661,0.654,0.647,0.64,0.633};

        double[] four = new double[]{0.55,0.626,0.619,0.613,0.606,0.599,0.592,
                0.585,0.578,0.571,0.564,0.557,0.55};

        double[] five = new double[]{0.467,0.543,0.536,0.529,0.522,0.515,0.508,
                0.501,0.494,0.488,0.481,0.474,0.467};

        double[] six = new double[]{0.383,0.46,0.453,0.446,0.439,0.432,0.425,
                0.418,0.411,0.404,0.397,0.39,0.383};


        double[]  seven = new double[] {0.3,0.376,0.369,0.363,0.356,0.349,0.342,
                0.335,0.328,0.321,0.314,0.307,0.3};


        double[]  eight = new double[] {0.217,0.293,0.286,0.279,0.272,0.265,0.258,
                0.251,0.244,0.238,0.231,0.224,0.217};


        double[]  nine = new double[]{0.133,0.21,0.203,0.196,0.189,0.182,0.175,
                0.168,0.161,0.154,0.147,0.14,0.133};


        double[]  ten  = new double[]{0.05,0.126,0.119,0.113,0.106,0.099,0.092,
                0.085,0.078,0.071,0.064,0.057,0.005};

        double[][]  all = new double[][]{one,two,three,four,five,six,seven,eight,nine,ten};
        for (int y = 1; y <= 10; y++) {
            for (int m = 0; m <= 12; m++) {
                cityBuilder.put(y,m,new BigDecimal(all[y - 1][m]));
                logger.info(y + "#" + m + "#" + all[y - 1][m]);
            }
        }

        one = two = three = four = five = six = seven = eight = nine = ten = null;
        all = null;
        cityTable = cityBuilder.build();
    }


    static {
        ImmutableTable.Builder<Integer,Integer,BigDecimal>   constructionBuilder = ImmutableTable.builder();


        double[] one = new double[] {0.667,0.972,0.944,0.917,0.889,0.861,0.833,
                0.806,0.778,0.75,0.722,0.694,0.667};

        double[] two = new double[] {0.444,0.648,0.63,0.611,0.593,0.574,0.556,
                0.537,0.519, 0.5,0.481,0.463,0.444};

        double[] three = new double[]{0.358,0.437,0.43,0.423,0.416,0.409,0.401,
                0.394,0.387,0.38,0.373,0.366,0.358};

        double[] four = new double[] {0.272,0.351,0.344,0.337,0.33,0.322,0.315,
                0.308,0.301,0.294,0.287,0.279,0.272};

        double[] five = new double[]{0.186,0.265,0.258,0.251,0.244,0.236,0.229,
                0.222,0.215,0.208,0.2,0.193,0.186};

        double[] six = new double[]{0.1,0.179,0.172,0.165,0.157,0.15,0.143,
                0.136,0.129,0.122,0.114,0.107,0.1};

        double[][]  all = new double[][]{one,two,three,four,five,six};
        for (int y = 1; y <= 6; y++) {
            for (int m = 0; m <= 12; m++) {
                constructionBuilder.put(y,m,new BigDecimal(all[y - 1][m]));
                logger.info(y + "#" + m + "#" + all[y - 1][m]);
            }
        }

        one = two = three = four = five = six = null;
        all = null;
        constructionTable= constructionBuilder.build();
    }


    public static ImmutableTable<Integer,Integer,BigDecimal>  getTable(int use) {
        return use == 1 ? carryTable : (use == 2 ? cityTable : (use == 3 ? constructionTable : null));
    }



}
